package model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Observable;

public class AdminQuery extends Observable{
	public static AdminQuery obs = null;
	public AdminQuery(){
		obs=this;
	}
	public int getCountUtnOfSector(int sector){
		int count=0;
		try {
			if (sector!=600){
				ResultSet result = Database.getQueryResult("SELECT COUNT(acc_id) FROM account WHERE level="+sector);
				while(result.next())
					count=result.getInt(1);
			}
			else{
				ResultSet result = Database.getQueryResult("SELECT COUNT(acc_id) FROM account");
				while(result.next())
					count=result.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}
	public int getCountEvnOfType(String type){
		int count=0;

		try {
			if (!type.contentEquals("512")){
				ResultSet result = Database.getQueryResult("SELECT COUNT(evn_id) FROM evento WHERE type='"+type+"'");
				while(result.next())
					count=result.getInt(1);
			}
			else{
				ResultSet result = Database.getQueryResult("SELECT COUNT(evn_id) FROM evento");
				while(result.next())
					count=result.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}
}
